<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

defined('_JEXEC') or die('Restricted access');

class JobBoardControllerJAJobAlerts extends JobBoardController{

    /**
     * Constructor
     */
    function __construct( $default = array() )
    {
        parent::__construct( $default );
        $this->set('name', 'jobalerts');
        $this->set('fullname', JBPREFIX.'jobalerts');
        $layout = JRequest::getVar("layout");
        if($layout=="delete")
        	$this->delete();
        
        // Register Extra tasks
//        $this->registerTask('unstarred', 'starred');
     }
     
	function save(){
		global $option;
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
		$cache = & JFactory::getCache($option);
		$cache->clean();

		$model	=& $this->getModel('jajobalerts');
		$post	= JRequest::get('post');
					
		$model->setState( 'request', $post );
		if ($id = $model->store()) {
			if ((isset($cid[0]))&&$cid[0]!=0)
				$msg = JText::_( 'Successfully updated job alert' );
			else 
				$msg = JText::_( 'Successfully created job alert' );
		} else {
			$msg = JText::_( 'Error found!Fail to save job alert' );
		}
		
		$this->setRedirect( JRoute::_("index.php?option=$option&view=jajobalerts&Itemid=".JRequest::getVar("Itemid")), $msg );
		}

		function delete()
		{
			global $option;
			$model = $this->getModel("jajobalerts");
			$model->delete();
			$this->setRedirect(JRoute::_("index.php?option=$option&view=jajobalerts&Itemid=".JRequest::getVar("Itemid")));
		}
		
	}     


?>
